import { EnumSchema } from '#/common';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 设备警报状态枚举 */
export enum DeviceAlarmStatusEnum {
  /** 未知 */
  Unset = 0,
  /** 正常 */
  Normal = 1,
  /** 异常 */
  Abnormal = 2,
}

/** 设备警报状态实体 */
export class DeviceAlarmStatusEntity {
  /** 设备警报状态 */
  AlarmStatus: DeviceAlarmStatusEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(alarmStatus: DeviceAlarmStatusEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.AlarmStatus = alarmStatus;
    this.Color = color;
    switch (alarmStatus) {
      case DeviceAlarmStatusEnum.Unset:
        // this.Display = '未知';
        this.Display = t('iot.enum.deviceAlarmStatus.unset');
        this.Color = this.Color ? this.Color : PresetColorEnum.Default;
        break;
      case DeviceAlarmStatusEnum.Normal:
        // this.Display = '正常';
        this.Display = t('iot.enum.deviceAlarmStatus.normal');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case DeviceAlarmStatusEnum.Abnormal:
        // this.Display = '异常';
        this.Display = t('iot.enum.deviceAlarmStatus.abnormal');
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
    }
  }
}

//#region 获取设备警报状态枚举架构
/**
 * 获取设备警报状态枚举架构
 */
export function getDeviceAlarmStatusEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DeviceAlarmStatusEntity[] = [
    new DeviceAlarmStatusEntity(DeviceAlarmStatusEnum.Unset),
    new DeviceAlarmStatusEntity(DeviceAlarmStatusEnum.Normal),
    new DeviceAlarmStatusEntity(DeviceAlarmStatusEnum.Abnormal),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.AlarmStatus as number,
      label: item.Display,
      value: item.AlarmStatus as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
